import AOP.CaLcImpl;
import AOP.Calc1;
import AOP.Calc1ImplDynamicProxy;
import AOP.Calc1ImplStaticProxy;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import config.DruidConfig;
import config.JdbcProperties;
import config.SpringConfig;
import model.Student;


import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.SQLException;

public class testStudent {
    @Test
    public void test() throws SQLException {
        //创建容器对象
//        ApplicationContext  ioc =new ClassPathXmlApplicationContext("spring.xml");
//        //从容器获取Student
//        Student bean = ioc.getBean(Student.class);
//        System.out.println("bean = " + bean);
//        ApplicationContext ioc2 = new AnnotationConfigApplicationContext(SpringConfig.class);
//        Student bean2 = ioc2.getBean(Student.class);
//        System.out.println("bean = " + bean2);


    }
    @Test
    public void testSpring(){
        //创建容器对象(基于配置类)
        ConfigurableApplicationContext ioc = new AnnotationConfigApplicationContext(SpringConfig.class);
        //从容器中获取Student对象
//        Student bean = ioc.getBean(Student.class);
//        System.out.println("bean = " + bean);
        //关闭IOC容器对象
        ioc.close();


    }

    @Test
    public void test2(){
        //创建代理对象
        Calc1ImplStaticProxy proxy = new Calc1ImplStaticProxy(new CaLcImpl());
        //调用方法
        int rs = proxy.add(1, 2);
        System.out.println("rs = " + rs);
    }
    @Test
    public void testDynamicProxy() {
        //创建动态代理工具类
        Calc1ImplDynamicProxy dp = new Calc1ImplDynamicProxy(new  CaLcImpl());
        //代理对象
//        Calc1Impl proxy = (Calc1Impl) dp.getProxy();   //错误(**代理对象不能转换为目标对象**)
        Calc1 proxy = (Calc1) dp.getProxy();
        System.out.println("proxy.getClass().getName() = " + proxy.getClass().getName());
        int add = proxy.add(1, 2);
    }





    @Test
   public void testAOP(){
        System.out.println("calc.getClass().getName() = " + calc.getClass().getName());
        calc.add(1,2);
    }

}

